package com.huawei.appgallery.appcomment.ui;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import com.huawei.appgallery.appcomment.api.IUserCommentListFragmentProtocol;
import com.huawei.appgallery.appcomment.impl.bean.UserCommentInfoCardBean;
import com.huawei.appgallery.appcomment.ui.usercomment.UserCommentInfoCard;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.fragment.AppListFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import o.bcb;
import o.bcg.h;
import o.bcg.i;
import o.bcz;
import o.bda;
import o.bdr;
import o.bdu;
import o.bdz;
import o.bec;
import o.bmt;
import o.cdb;
import o.cdg;
import o.cdh;
import o.cdk;
import o.cdz;
import o.cfw;
import o.cgs;
import o.chz;
import o.cih;
import o.cks;
import o.cku;
import o.ckv;
import o.cvt;
import o.fjm;
import o.ll;

@FragmentDefine(alias = "MyCommentListFragment", protocol = IUserCommentListFragmentProtocol.class)
public class MyCommentListFragment extends AppListFragment<AppListFragmentProtocol> {
    private static String ᐝ = "forum|user_detail_review_comment";
    private fjm ʹ = fjm.ॱ(this);
    protected String ˊ = "";
    private bec ॱॱ;
    private final BroadcastReceiver ﹳ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ MyCommentListFragment ˎ;

        {
            this.ˎ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            SafeIntent safeIntent = new SafeIntent(intent);
            Serializable serializableExtra;
            if ("com.huawei.appmarket.service.broadcast.Approved".equals(safeIntent.getAction())) {
                try {
                    serializableExtra = safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_APPROVED");
                    if (serializableExtra != null && (serializableExtra instanceof o.bdm.e)) {
                        this.ˎ.ॱॱ.ˏ((o.bdm.e) serializableExtra, this.ˎ.י);
                    }
                } catch (Throwable e) {
                    bcb.ˋ.ˊ("MyCommentListFragment", "ACTION_COMMENT_APPROVED error!!", e);
                }
            } else if ("com.huawei.appmarket.service.broadcast.Dissed".equals(safeIntent.getAction())) {
                try {
                    serializableExtra = safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_DISSED");
                    if (serializableExtra != null && (serializableExtra instanceof o.bdm.e)) {
                        this.ˎ.ॱॱ.ˏ((o.bdm.e) serializableExtra, this.ˎ.י);
                    }
                } catch (Throwable e2) {
                    bcb.ˋ.ˊ("MyCommentListFragment", "ACTION_COMMENT_DISS error!!", e2);
                }
            } else if ("com.huawei.appmarket.service.broadcast.CommentReplyAdded".equals(safeIntent.getAction())) {
                try {
                    this.ˎ.ॱॱ.ˋ(safeIntent.getStringExtra("ACTION_PARAM_COMMENT_REPLY_ADDED_TYPE_COMMENTID"), safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_APPID"), this.ˎ.י);
                } catch (Throwable e22) {
                    bcb.ˋ.ˊ("MyCommentListFragment", "ACTION_COMMENT_REPLY_ADDED error!!!", e22);
                }
            } else if ("com.huawei.appmarket.service.broadcast.CommentAdded".equals(safeIntent.getAction())) {
                this.ˎ.ॱॱ.ॱ(safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_APPID"), safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_RATING"), safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_CONTENT"), this.ˎ.י);
            } else if ("com.huawei.appmarket.service.broadcast.CommentDeleted".equals(safeIntent.getAction())) {
                String stringExtra = safeIntent.getStringExtra("ACTION_PARAM_COMMENT_DEL_TYPE_COMMENTID");
                bcb.ˋ.ˎ("MyCommentListFragment", "delete Comment: commentId=" + stringExtra);
                this.ˎ.ˎ(stringExtra);
            }
        }
    };
    private PopupMenu ﾞ = null;

    class c implements OnMenuItemClickListener {
        final /* synthetic */ MyCommentListFragment ˊ;
        String ˋ;
        String ˎ;
        String ˏ;

        public c(MyCommentListFragment myCommentListFragment, String str, String str2, String str3) {
            this.ˊ = myCommentListFragment;
            this.ˏ = str;
            this.ˋ = str2;
            this.ˎ = str3;
        }

        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == o.bcg.e.ʽˊ) {
                this.ˊ.ˎ(this.ˏ, this.ˋ, this.ˎ);
            }
            return false;
        }
    }

    class e implements bdz {
        final /* synthetic */ MyCommentListFragment ˏ;
        cih ॱ;

        public e(MyCommentListFragment myCommentListFragment, cih o_cih) {
            this.ˏ = myCommentListFragment;
            this.ॱ = o_cih;
        }

        public void ˊ() {
            this.ˏ.ˏ(this.ॱ);
        }

        public void ˋ() {
        }
    }

    public static MyCommentListFragment ॱ(String str) {
        MyCommentListFragment myCommentListFragment = new MyCommentListFragment();
        Bundle bundle = new Bundle();
        bundle.putString("app_comments_list_request_accountid", str);
        myCommentListFragment.ʼ(bundle);
        return myCommentListFragment;
    }

    private void ˎ(String str) {
        if (this.י != null && !TextUtils.isEmpty(str)) {
            for (chz o_chz : this.י.ʻॱ()) {
                if (!(o_chz == null || cgs.ˋ(o_chz.ˎ))) {
                    List list = o_chz.ˎ;
                    Iterator it = list.iterator();
                    while (it.hasNext()) {
                        BaseCardBean baseCardBean = (BaseCardBean) it.next();
                        if ((baseCardBean instanceof UserCommentInfoCardBean) && str.equals(((UserCommentInfoCardBean) baseCardBean).ˊ().ॱᐝ())) {
                            it.remove();
                            break;
                        }
                    }
                    this.י.ͺ();
                    if (list.size() == 0) {
                        ˋॱ(false);
                    }
                }
            }
        }
    }

    public void ˏ(Bundle bundle) {
        ˋॱ(102011);
        this.ˊ = ˊॱ().getString("app_comments_list_request_accountid");
        IUserCommentListFragmentProtocol iUserCommentListFragmentProtocol = (IUserCommentListFragmentProtocol) this.ʹ.ॱ();
        if (iUserCommentListFragmentProtocol != null && TextUtils.isEmpty(this.ˊ)) {
            this.ˊ = iUserCommentListFragmentProtocol.getUserId();
        }
        super.ˏ(bundle);
        this.ॱॱ = new bec(ॱˋ());
        this.ˏͺ = 5;
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View ˋ = super.ˋ(layoutInflater, viewGroup, bundle);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Approved");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Dissed");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentReplyAdded");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentAdded");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentDeleted");
        ll.ˏ(ॱˋ()).ˏ(this.ﹳ, intentFilter);
        return ˋ;
    }

    public void ᐝ() {
        super.ᐝ();
        ll.ˏ(ॱˋ()).ˋ(this.ﹳ);
    }

    public void ॱ(NodataWarnLayout nodataWarnLayout) {
        if (nodataWarnLayout != null) {
            nodataWarnLayout.setWarnImage(o.bcg.c.ˊ);
            nodataWarnLayout.setWarnTextOne(h.ˈ);
            nodataWarnLayout.setViewVisible(com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout.e.WARN_BTN, 8);
            nodataWarnLayout.setViewVisible(com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout.e.WARN_TEXTTWO, 8);
        }
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(ᐝ);
        if (!TextUtils.isEmpty(this.ˊ)) {
            stringBuilder.append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(this.ˊ);
        }
        list.add(new bda(stringBuilder.toString(), this.ˏ));
    }

    public void ˏ(int i, cih o_cih) {
        if (o_cih != null) {
            if (i == 1001) {
                this.ॱॱ.ˎ(o_cih);
            } else if (i == 1002) {
                r0 = cdz.ˎ();
                r1 = UserSession.getInstance().getUserId();
                r2 = h.ॱꜟ;
                cdk.ॱ(ॱˋ(), cdk.ˏ(ॱˋ(), r2), "02|" + r1 + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + r0);
                if (bmt.ˊ(ॱˋ())) {
                    r0 = o_cih.ˌ();
                    if ((r0 instanceof UserCommentInfoCardBean) && (o_cih instanceof UserCommentInfoCard)) {
                        this.ॱॱ.ॱ((UserCommentInfoCardBean) r0, (UserCommentInfoCard) o_cih, true);
                        return;
                    }
                    return;
                }
                ckv.ˎ(ॱˋ().getString(h.ᐝʽ), 0);
            } else {
                if (i == 1003) {
                    r0 = cdz.ˎ();
                    r1 = UserSession.getInstance().getUserId();
                    r2 = h.ॱꜟ;
                    cdk.ॱ(ॱˋ(), cdk.ˏ(ॱˋ(), r2), "03|" + r1 + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + r0);
                    if (bmt.ˊ(ॱˋ())) {
                        r0 = o_cih.ˌ();
                        if (r0 instanceof UserCommentInfoCardBean) {
                            this.ॱॱ.ˏ(r0);
                            return;
                        }
                    }
                    ckv.ˎ(ॱˋ().getString(h.ᐝʽ), 0);
                    return;
                } else if (i == 1004) {
                    if (ˋ(o_cih)) {
                        return;
                    }
                } else if (i == 1008) {
                    new bdr(ॱˋ(), new e(this, o_cih)).ˎ();
                    return;
                }
                super.ˏ(i, o_cih);
            }
        }
    }

    private boolean ˋ(cih o_cih) {
        CardBean ˌ = o_cih.ˌ();
        if (!(ˌ instanceof UserCommentInfoCardBean)) {
            return false;
        }
        String valueOf;
        UserCommentInfoCard userCommentInfoCard = (UserCommentInfoCard) o_cih;
        UserCommentInfoCardBean userCommentInfoCardBean = (UserCommentInfoCardBean) ˌ;
        PackageInfo packageInfo = null;
        if (!TextUtils.isEmpty(userCommentInfoCardBean.ॱـ())) {
            packageInfo = ((cdg) cdb.ॱ(cdg.class)).ᐝ(userCommentInfoCardBean.ॱـ());
        }
        if (packageInfo != null) {
            valueOf = String.valueOf(packageInfo.versionCode);
        } else {
            valueOf = userCommentInfoCardBean.ˎˎ();
        }
        ˊ(userCommentInfoCard.ᐝ(), userCommentInfoCardBean.ˊ().ॱᐝ(), valueOf, userCommentInfoCardBean.ͺˏ());
        return true;
    }

    private boolean ˏ(cih o_cih) {
        if (bmt.ˊ(ॱˋ())) {
            CardBean ˌ = o_cih.ˌ();
            if ((ˌ instanceof UserCommentInfoCardBean) && (o_cih instanceof UserCommentInfoCard)) {
                this.ॱॱ.ॱ((UserCommentInfoCardBean) ˌ, (UserCommentInfoCard) o_cih, false);
            }
            return false;
        }
        ckv.ˎ(ॱˋ().getString(h.ᐝʽ), 0);
        return true;
    }

    private void ˊ(View view, String str, String str2, String str3) {
        if (view != null) {
            this.ﾞ = new PopupMenu(view.getContext(), view);
            this.ﾞ.getMenuInflater().inflate(i.ˎ, this.ﾞ.getMenu());
            this.ﾞ.setOnMenuItemClickListener(new c(this, str, str2, str3));
            this.ﾞ.show();
        }
    }

    private void ˎ(final String str, final String str2, final String str3) {
        Context ॱˋ = ॱˋ();
        if (ॱˋ != null) {
            CharSequence string = ॱˋ.getString(h.ᐧ);
            cku ˋ = cku.ˋ(null, ॱˋ.getString(h.ꞌ));
            ˋ.ˎ(ॱˋ);
            ˋ.ॱ(-1, string);
            ˋ.ॱ(new cks(this) {
                final /* synthetic */ MyCommentListFragment ˎ;

                public void enableNetworking() {
                    this.ˎ.ˋ(str, str2, str3);
                }

                public void upgrade() {
                }

                public void ˋ() {
                }
            });
        }
    }

    private void ˋ(String str, String str2, String str3) {
        Context ʻॱ = AbstractBaseActivity.ʻॱ();
        if (ʻॱ == null) {
            bcb.ˋ.ˋ("MyCommentListFragment", "current Activity is null");
        } else if (bmt.ˊ(ʻॱ)) {
            cvt o_bcz = new bcz(str);
            o_bcz.setServiceType_(cdh.ˎ(ʻॱ));
            cfw.ˎ(o_bcz, new bdu(str, str2, str3, ʻॱ));
        } else {
            ckv.ˎ(ʻॱ.getString(h.ᐝʽ), 0);
        }
    }
}
